<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2022/5/25
  Time: 8:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="header.jsp"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%--${student}--%>
    <form id="formId" class="layui-form layui-form-pane" action="">
        <%--因为是根据id来更新，所以也要把这个id提交到后台去--%>
        <input type="hidden" name="id" value="${student.id}"/>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" value="${student.name}" name="name" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-block">
                <input type="text" value="${student.age}" name="age" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" pane="">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <c:if test="${student.gender=='男'}">
                    <input type="radio" name="gender" value="男" title="男" checked="">
                </c:if>
                <c:if test="${student.gender!='男'}">
                    <input type="radio" name="gender" value="男" title="男">
                </c:if>

                <c:if test="${student.gender=='女'}">
                    <input type="radio" name="gender" value="女" title="女" checked="">
                </c:if>
                <c:if test="${student.gender!='女'}">
                    <input type="radio" name="gender" value="女" title="女">
                </c:if>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" onclick="submitForm()" >更新</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>
        function submitForm() {
            $.post(
                '/student/update',
                $('#formId').serialize(), // {'name':'zhansgan','age':23}
                function (jsonResult) {
                    if (jsonResult.ok) {
                        // 弹出成功提示消息，消息消失时候关闭这个弹出框
                        layer.msg(
                            jsonResult.msg,
                            {icon : 1, time : 2000},
                            function() {// msg消失之后触发的函数
                                // 获得当前弹出框的index
                                let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                parent.location.reload();//刷新父级页面
                            }
                        );
                    }
                },
                'json'
            );
        }
    </script>
</body>
</html>
